from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-08 14:05:34.076470
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 08, Oct, 2022
Time: 14:05:39
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6391
Nobs: 803.000 HQIC: -50.9627
Log likelihood: 10377.9 FPE: 6.01907e-23
AIC: -51.1645 Det(Omega_mle): 5.38461e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297067 0.052814 5.625 0.000
L1.Burgenland 0.109199 0.035521 3.074 0.002
L1.Kärnten -0.106406 0.018911 -5.627 0.000
L1.Niederösterreich 0.210158 0.074290 2.829 0.005
L1.Oberösterreich 0.100157 0.071270 1.405 0.160
L1.Salzburg 0.251622 0.037872 6.644 0.000
L1.Steiermark 0.038225 0.049551 0.771 0.440
L1.Tirol 0.106223 0.040179 2.644 0.008
L1.Vorarlberg -0.059224 0.034540 -1.715 0.086
L1.Wien 0.057517 0.063637 0.904 0.366
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064157 0.109350 0.587 0.557
L1.Burgenland -0.033529 0.073547 -0.456 0.648
L1.Kärnten 0.047843 0.039155 1.222 0.222
L1.Niederösterreich -0.172265 0.153816 -1.120 0.263
L1.Oberösterreich 0.385064 0.147564 2.609 0.009
L1.Salzburg 0.287174 0.078413 3.662 0.000
L1.Steiermark 0.106115 0.102594 1.034 0.301
L1.Tirol 0.313406 0.083190 3.767 0.000
L1.Vorarlberg 0.025225 0.071514 0.353 0.724
L1.Wien -0.016532 0.131760 -0.125 0.900
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190037 0.027113 7.009 0.000
L1.Burgenland 0.090157 0.018235 4.944 0.000
L1.Kärnten -0.008442 0.009708 -0.870 0.385
L1.Niederösterreich 0.264530 0.038138 6.936 0.000
L1.Oberösterreich 0.126575 0.036588 3.459 0.001
L1.Salzburg 0.047494 0.019442 2.443 0.015
L1.Steiermark 0.017047 0.025438 0.670 0.503
L1.Tirol 0.094286 0.020627 4.571 0.000
L1.Vorarlberg 0.059287 0.017731 3.344 0.001
L1.Wien 0.120088 0.032669 3.676 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109888 0.027784 3.955 0.000
L1.Burgenland 0.044397 0.018687 2.376 0.018
L1.Kärnten -0.016086 0.009949 -1.617 0.106
L1.Niederösterreich 0.193272 0.039082 4.945 0.000
L1.Oberösterreich 0.293996 0.037494 7.841 0.000
L1.Salzburg 0.114994 0.019924 5.772 0.000
L1.Steiermark 0.099933 0.026068 3.834 0.000
L1.Tirol 0.116270 0.021137 5.501 0.000
L1.Vorarlberg 0.070583 0.018171 3.884 0.000
L1.Wien -0.027604 0.033478 -0.825 0.410
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129019 0.050386 2.561 0.010
L1.Burgenland -0.051264 0.033889 -1.513 0.130
L1.Kärnten -0.040294 0.018042 -2.233 0.026
L1.Niederösterreich 0.170446 0.070875 2.405 0.016
L1.Oberösterreich 0.137520 0.067994 2.023 0.043
L1.Salzburg 0.285828 0.036131 7.911 0.000
L1.Steiermark 0.034875 0.047273 0.738 0.461
L1.Tirol 0.164253 0.038332 4.285 0.000
L1.Vorarlberg 0.103736 0.032952 3.148 0.002
L1.Wien 0.068146 0.060712 1.122 0.262
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060091 0.039948 1.504 0.133
L1.Burgenland 0.038502 0.026869 1.433 0.152
L1.Kärnten 0.050663 0.014304 3.542 0.000
L1.Niederösterreich 0.225924 0.056193 4.020 0.000
L1.Oberösterreich 0.282185 0.053909 5.234 0.000
L1.Salzburg 0.050865 0.028646 1.776 0.076
L1.Steiermark -0.007145 0.037480 -0.191 0.849
L1.Tirol 0.149807 0.030392 4.929 0.000
L1.Vorarlberg 0.070936 0.026126 2.715 0.007
L1.Wien 0.079120 0.048136 1.644 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180128 0.047782 3.770 0.000
L1.Burgenland -0.006153 0.032137 -0.191 0.848
L1.Kärnten -0.061100 0.017109 -3.571 0.000
L1.Niederösterreich -0.083828 0.067212 -1.247 0.212
L1.Oberösterreich 0.193813 0.064480 3.006 0.003
L1.Salzburg 0.057130 0.034264 1.667 0.095
L1.Steiermark 0.231454 0.044830 5.163 0.000
L1.Tirol 0.493814 0.036351 13.585 0.000
L1.Vorarlberg 0.049060 0.031249 1.570 0.116
L1.Wien -0.052027 0.057575 -0.904 0.366
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162027 0.054826 2.955 0.003
L1.Burgenland -0.011176 0.036875 -0.303 0.762
L1.Kärnten 0.065969 0.019632 3.360 0.001
L1.Niederösterreich 0.201056 0.077121 2.607 0.009
L1.Oberösterreich -0.061552 0.073986 -0.832 0.405
L1.Salzburg 0.215982 0.039315 5.494 0.000
L1.Steiermark 0.114092 0.051439 2.218 0.027
L1.Tirol 0.076856 0.041710 1.843 0.065
L1.Vorarlberg 0.124311 0.035856 3.467 0.001
L1.Wien 0.114584 0.066062 1.734 0.083
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354102 0.031902 11.100 0.000
L1.Burgenland 0.006151 0.021456 0.287 0.774
L1.Kärnten -0.023547 0.011423 -2.061 0.039
L1.Niederösterreich 0.224030 0.044874 4.992 0.000
L1.Oberösterreich 0.175421 0.043050 4.075 0.000
L1.Salzburg 0.046953 0.022876 2.052 0.040
L1.Steiermark -0.017077 0.029931 -0.571 0.568
L1.Tirol 0.108582 0.024270 4.474 0.000
L1.Vorarlberg 0.073467 0.020863 3.521 0.000
L1.Wien 0.053261 0.038440 1.386 0.166
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041135 0.152664 0.190361 0.157117 0.125055 0.113213 0.065665 0.226893
Kärnten 0.041135 1.000000 -0.002558 0.129720 0.041397 0.096100 0.429244 -0.053153 0.101341
Niederösterreich 0.152664 -0.002558 1.000000 0.337038 0.155272 0.300436 0.111137 0.183808 0.327599
Oberösterreich 0.190361 0.129720 0.337038 1.000000 0.232457 0.332805 0.172618 0.172318 0.263108
Salzburg 0.157117 0.041397 0.155272 0.232457 1.000000 0.146577 0.127336 0.149038 0.135647
Steiermark 0.125055 0.096100 0.300436 0.332805 0.146577 1.000000 0.153230 0.141049 0.079742
Tirol 0.113213 0.429244 0.111137 0.172618 0.127336 0.153230 1.000000 0.115104 0.154795
Vorarlberg 0.065665 -0.053153 0.183808 0.172318 0.149038 0.141049 0.115104 1.000000 0.007160
Wien 0.226893 0.101341 0.327599 0.263108 0.135647 0.079742 0.154795 0.007160 1.000000